package com.sys.management.controller;

import com.sys.management.mapper.service.evaluationService;
import com.sys.management.mapper.service.informationService;
import com.sys.management.pojo.evaluationmanagement;
import com.sys.management.pojo.evaluationvo;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

@RestController
public class evaluationController {
    @Resource
    private evaluationService evaSer;

    @Resource
    private informationService inser;

    @RequestMapping("/evaluation")
    @ResponseBody
    //显示员工评价信息
    public List<evaluationvo> showInfo(){
        List<evaluationvo> evaluationvos = evaSer.mutiSearch();
        return evaluationvos;

    }

    //添加评论
    @RequestMapping("/evaluation/addEva")
    public String addEva(@RequestParam("eid") String eid,
                         @RequestParam("isbreak") String isbreak,
                         @RequestParam("breakexplain") String breakexplain,
                         @RequestParam("isrewardisreward") String isreward,
                         @RequestParam("rewardexplain") String rewardexplain,
                         @RequestParam("evacontent") String evacontent,
                         Model model){
        evaluationmanagement eva=new evaluationmanagement(eid,isbreak,breakexplain,isreward,rewardexplain,evacontent);
        boolean flag=evaSer.isExist(eva);//存在员工则添加评论
        if(!flag) {
            model.addAttribute("feedback", "本公司无此员工！");
        }
        else model.addAttribute("feedback", "添加成功！");
        return "redirect:/evaluation";
    }

    //按eid查询
    @RequestMapping("/evaluation/selectById")
    @ResponseBody
    public evaluationvo selectByeId(@RequestParam("eid") String eid) throws ParseException {
        evaluationvo evoo=null;
        List<evaluationvo> evaluationvos = evaSer.mutiSearch();
        for(evaluationvo evo:evaluationvos){
            if(evo.getEid().equals(eid)) {
                evoo=evo;
            }
        }
        return evoo;
    }


    //按部门查询
    @RequestMapping("/evaluation/selectByDepartment")
    @ResponseBody
    public evaluationvo selectByDepatment(@RequestParam("edepartment") String edepartment) throws ParseException {
        evaluationvo evoo=null;
        List<evaluationvo> evaluationvos = evaSer.mutiSearch();
        for(evaluationvo evo:evaluationvos){
            if(evo.getEdepartment().equals(edepartment)) {
                evoo=evo;
            }
        }
        return evoo;
    }

    //导出Excel
    @RequestMapping("/evaluation/exportExel")
    public void exploreExcel() throws Exception {
        List<evaluationvo> evaluationvos=evaSer.mutiSearch();
        evaSer.exportExel("员工评价记录表",evaluationvos);
    }
}

